#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>
typedef int StackDataType;
typedef struct Stack
{
	StackDataType* arr;
	int size;
	int capacity;
}sk;
void StackInit(sk* ps)
{
	assert(ps);
	ps->arr = NULL;
	ps->capacity = ps->size = 0;
}
void StackDestroy(sk* ps)
{
	assert(ps);
	if (ps->capacity != 0)
	{
		free(ps->arr);
	}
}
void StackPush(sk* ps, StackDataType x)
{
	assert(ps);
	if (ps->capacity == ps->size)
	{
		int newcapacity =ps->capacity == 0 ? 4 : ps->capacity * 2;
		StackDataType* new = (StackDataType*)realloc(ps->arr, 2*sizeof(StackDataType) * newcapacity);
		if (new == NULL)
		{
			perror("realloc fail!");
			printf("\n");
			return;
		}
		ps->arr = new;
		ps->capacity = newcapacity;
	}
	ps->arr[ps->size] = x;
	ps->size++;
}
void StackPop(sk* ps)
{
	assert(ps);
	ps->size--;
}
StackDataType StackGetData(sk* ps)
{
	assert(ps);
	return ps->arr[ps->size-1];
}
void StackPrint( sk ps)
{
	while (ps.size)
	{
		printf("%d\n", ps.arr[ps.size-1]);
		ps.size--;
	}
}
bool StackJudge(sk* ps)
{
	assert(ps);
	if (ps->size == 0)
	{
		return 1;
	}
	return 0;
}
int StackSize(sk* ps)
{
	assert(ps);
	return ps->size;
 }
int main()
{
	sk plist;
	StackInit(&plist);
	StackPush(&plist, 1);
	StackPush(&plist, 2);
	StackPush(&plist, 3);
	StackPush(&plist, 4);
	StackPrint(plist);
	printf("%d\n", StackGetData(&plist));
	printf("%d\n", StackSize(&plist));
	//StackDestroy(&plist);
	return 0;
}